home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: CItemApp.c
- * Created: 8/1/93
- * Desc: A mousetask that handles dragging and dropping
- * in CItemTable.
- *
- * Superclass: CApplication.
- * Original Author: W. Wesley Monroe
- * Modifications: Atul Barve
- *
- * Copyright © 1993 Animas Software Production. All rights reserved.
- */
-
- #include "CItemApp.h"
- #include "Commands.h"
- #include "ItemCommands.h"
- #include "CBartender.h"
- #include "CPane.h"
- #include "CPaneBorder.h"
- #include "CItemTableDemo.h"
- #include "CAppleEvent.h"
-
- // to suppress class stripping only
- #include "CButton.h"
- #include "CRadioControl.h"
- #include "CRadioGroupPane.h"
- #include "CStdPopupPane.h"
- #include "CArrowPopupPane.h"
- #include "CCheckBox.h"
- #include "CIconPane.h"
- #include "CIntegerText.h"
-
- #define kExtraMasters 10 // #times to call MoreMasters
- #define kRainyDayFund 45000 // total size of rainyDay memory reserve
- #define kCriticalBalance 40000 // portion of rainyDay saved for critical operations
- #define kToolboxBalance 20000 // portion of rainyDay saved for toolbox calls
- // and other operations that must not fail
-
- #define MENUdialogs 1000 // dialog menu ID
-
- #define kItemDialog1 1026 // resource IDs of demo dialogs
- #define kItemDialog2 1027
- #define kItemDialog3 1028
- #define kItemDialog4 1029
-
- // global variables used in this file
-
- extern CClipboard *gClipboard;
- extern CDesktop *gDesktop;
- extern CBartender *gBartender;
- extern OSType gSignature;
-
- /******************************************************************************
- CItemApp
-
- Initialize the global application object.
- ******************************************************************************/
-
- CItemApp::CItemApp( void)
- {
- // call CApplication's initialization method, indicating the
- // number of times to call MoreMasters, the size of the rainy day
- // fund memory reserve, and the critical operation and toolbox
- // balances
-
- CApplication::IApplication( kExtraMasters, kRainyDayFund,
- kCriticalBalance, kToolboxBalance);
-
- // The task names used in the undo menu item are stored
- // in STR# 130, in whatever order you define. If you want
- // text editing to display the correct name, e.g. "Undo Typing"
- // then you must tell CAbstractText where its strings are in
- // the STR# 130 resource.
-
- CAbstractText::cFirstTaskIndex = 1; // first in the resource
-
- }
-
- /******************************************************************************
- MakeClipboard {OVERRIDE}
-
- We override MakeClipboard in order to create a subclass of
- CClipboard, CStyleTEClipboard, that can display styled text.
- ******************************************************************************/
-
- void CItemApp::MakeClipboard( void)
- {
- CClipboard *clip = new( CClipboard);
-
- clip->IClipboard( this, TRUE);
- gClipboard = clip;
- }
-
- /******************************************************************************
- SetUpFileParameters {OVERRIDE}
-
- You need to override SetUpFileParameters to specify your applications
- file creator signature, and the types of files your application can open.
- ******************************************************************************/
-
- void CItemApp::SetUpFileParameters(void)
- {
- inherited::SetUpFileParameters();
-
- sfNumTypes = 2; // we open two types of files:
- sfFileTypes[0] = 'TEXT'; // any text file,
- sfFileTypes[1] = 'rsrc'; // and resource files. ResEdit uses
- // 'rsrc' as the file type for files it creates
-
- gSignature = 'tclD'; // The file creator for files your application
- // creates
- }
-
- /******************************************************************************
- SetupMenus {OVERRIDE}
-
- We override SetupMenus in order to do some extra menu initialization.
- ******************************************************************************/
-
- void CItemApp::SetUpMenus( void)
- {
- // Creates the bartender, loads our MBAR, and installs the Apple menu
-
- inherited::SetUpMenus();
-
- // Turn off dimming and unchecking for the Font, size, and style menus
-
-
- gBartender->SetDimOption( MENUdialogs, dimNONE);
- }
-
- /******************************************************************************
- DoCommand {OVERRIDE}
-
- We override DoCommand to receive special commands handled by CItemApp
- ******************************************************************************/
-
- void CItemApp::DoCommand( long theCommand)
- {
- CDirector *director;
- CWindow *window;
-
- switch( theCommand)
- {
- case cmdNew :
- CreateDocument();
- break;
- default:
- inherited::DoCommand( theCommand);
- break;
- }
- }
-
- /******************************************************************************
- CreateDocument
-
- Here we display a dialog for the user to choose the type of document
- to create, and then send ourselves a DoCommand message with the command
- number corresponding to the selected document type.
- ******************************************************************************/
-
- void CItemApp::CreateDocument( void)
- {
- DoItemTable();
- }
-
- /******************************************************************************
- NewTextDoc
-
- Creates a new text document. If theCommand is cmdNewStyleText, the
- document will support styled text, else it supports only plain text.
- ******************************************************************************/
-
- void CItemApp::NewTextDoc( long theCommand)
- {
- }
-
-
- /******************************************************************************
- NewTableDoc
-
- Create a new ItemTable document.
- ******************************************************************************/
-
- void CItemApp::NewTableDoc( void)
- {
- }
-
- /******************************************************************************
- OpenDocument {OVERRIDE}
-
- Open an existing document. The type of document we open is depends upon
- the file type, as given in macReply.
- ******************************************************************************/
-
- void CItemApp::OpenDocument( SFReply *macReply)
- {
- }
-
- /******************************************************************************
- DoItemDialog
-
- Creates a dialog from the DLOG resource with the given ID. This method
- is used for several of the dialogs opened from the Dialogs menu.
- ******************************************************************************/
-
- CDirector *CItemApp::DoItemDialog( short resID, Boolean modal)
- {
- CDLOGDirector *dialog = NULL;
- long cmd;
-
- TRY
- {
- dialog = new CDLOGDirector;
- dialog->IDLOGDirector( resID, this);
- dialog->BeginDialog();
-
- if (modal)
- {
- cmd = dialog->DoModalDialog( cmdOK);
- ForgetObject( dialog);
- }
- }
- CATCH
- {
- ForgetObject( dialog);
- }
- ENDTRY;
-
- return dialog; // not null if dialog is non-modal
-
- }
-
- /******************************************************************************
- DoBorderDialog
-
- Creates the Borders demo dialog.
- ******************************************************************************/
-
- void CItemApp::DoBorderDialog( void)
- {
- CDocument *doc = NULL;
- CDLOGDialog *dlog;
- CPane *pane;
- short paneID;
-
- TRY
- {
- doc = new CDocument;
- doc->IDocument( this, kPrintable);
- dlog = new CDLOGDialog;
- doc->itsWindow = dlog;
- dlog->IDLOGDialog( kItemDialog4, gDesktop, doc);
-
- // there are 12 panes, with IDs 1-12, and 12 PBrd resources 128-139
- for (paneID = 1; paneID <= 12; paneID++)
- {
- pane = (CPane*) dlog->FindViewByID( paneID);
- if (pane)
- pane->SetResBorder( paneID + 127);
- }
-
- // set the main pane to the dialog panorama
- doc->itsMainPane = (CPane*) dlog->FindViewByID( kDialogPanoramaID);
-
- // size window so it fits on any screen
- dlog->ChangeSize( 480, 320);
-
- // show the window
- dlog->Select();
- }
- CATCH
- {
- ForgetObject( doc);
- }
- ENDTRY;
- }
-
- /******************************************************************************
- DoItemTable
-
- Creates the string table demo dialog
- ******************************************************************************/
-
- void CItemApp::DoItemTable( void)
- {
- CItemTableDemo *stringDlg = NULL;
-
- TRY
- {
- stringDlg = new CItemTableDemo;
- stringDlg->IItemTableDemo();
- stringDlg->BeginDialog();
- }
- CATCH
- {
- ForgetObject( stringDlg);
- }
- ENDTRY;
-
- }
-
- /******************************************************************************
- ForceClassReferences
-
- This method creates dummy references to classes that we don't want
- stripped out by the linker when the application is built. This could
- happen if the class is only created via new_by_name and is never directly
- referenced. CApplication automatically calls this method.
-
- ******************************************************************************/
-
-
- void CItemApp::ForceClassReferences( void)
- {
- Boolean alwaysFalse = FALSE;
- CObject *dummy = NULL;
-
- if (alwaysFalse == TRUE)
- {
- member( dummy, CButton);
- member( dummy, CCheckBox);
- member( dummy, CRadioControl);
- member( dummy, CRadioGroupPane);
- member( dummy, CIconPane);
- member( dummy, CIntegerText);
- member( dummy, CStdPopupPane);
- member( dummy, CArrowPopupPane);
- }
- }
-
-
- /******************************************************************************
- DoAppleEvent {OVERRIDE}
-
- When the user chooses File/New, CItemApp display a dialog for the
- user to choose the new doc type. Because of this interaction, we
- have to request user interation before handling the kAEOpenApplication
- AppleEvent.
-
- ******************************************************************************/
-
- void CItemApp::DoAppleEvent( CAppleEvent *anAppleEvent)
- {
- OSErr err;
- Boolean passIt = TRUE;
-
- if ((anAppleEvent->GetEventClass() == kCoreEventClass) &&
- (anAppleEvent->GetEventID() == kAEOpenApplication))
- {
- err = anAppleEvent->RequestInteraction( MAXLONG);
- if (err != noErr)
- passIt = FALSE;
- }
-
- if (passIt)
- inherited::DoAppleEvent( anAppleEvent);
-
- }
-